<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class scache extends CI_Model {

    function __construct() {
        parent::__construct();
    }
	
	function html(){
		 if($this->config->item('isCache')){
			$ci =& get_instance();
			$controler = $this->router->fetch_class();
			$class = $this->router->fetch_method();
			$cache = $this->config->item('cachePosition');
			$position = $controler."/".$class;
			if(array_key_exists($position,$cache)){
				$n = $cache[$position];
				$this->output->cache($n);
			}
		 }
	}
	
	function script($cache_name, $PHP_RunScript){
		$time_cache = $this->config->item('timeCacheFunction');//Seconds
		if($time_cache <=0){
			return eval("return ".$PHP_RunScript);
		}
		$this->load->driver('cache', array('adapter' => 'file', 'backup' => 'file'));
		if ( !$Data = $this->cache->get($cache_name))
		{
			$Data= eval("return ".$PHP_RunScript);
			$this->cache->save($cache_name, $Data, $time_cache);
		}
		return $Data;
	}
	
	function delete($cache_name){
		$this->cache->delete($cache_name);
	}
}

?>